package backtrackAlgorithm;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @className: backtrackAlgorithm.LeetCode_78
 * @Description: ...
 * @author: kunkun
 * @date: 2025/3/19 21:28
 */
public class LeetCode_78 {

    @Test
    public void test(){
        List<List<Integer>> lists = subsets(new int[]{1, 2, 3});
        for (List<Integer> list : lists) {
            for (Integer integer : list) {
                System.out.print(integer+" ");
            }
            System.out.println();
        }
    }

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> lists = new ArrayList<>();
        solution_1(0,lists,new ArrayList<Integer>(),nums);
        return lists;
    }

    private void solution_1(int index, List<List<Integer>> lists, ArrayList<Integer> list, int[] nums) {

        //1. 存储结果
        lists.add(new ArrayList<Integer>(list));

        //2. 循环遍历
        for (int i = index;i<nums.length;i++){
            list.add(nums[i]);
            solution_1(i+1,lists,list,nums);
            list.remove(list.size()-1);
        }
    }
}
